﻿using System.IO;
using Ninject;
using NUnit.Framework;

using System.Net.DnsToolkit.Packet;
using System.Net.DnsToolkit.Serializer;
using System.Net.DnsToolkit.Configuration;
using System.Net.DnsToolkit.Bastard.PacketGenerator;
using System.Net.DnsToolkit.Util;
using System.Net.DnsToolkit.TestUnit.Helper;

namespace System.Net.DnsToolkit.TestUnit.Bastard.PacketGenerator {

    [TestFixture]
    public class SelfAnsweringQuestionTest {

        [Test]
        public void TestGetMessage() {

            var generator = new SelfAnsweringQuestion();
            var message = generator.GetMessage();

            Assert.AreEqual(1, message.Header.QuestionCount, "Header.QuestionCount");
            Assert.AreEqual(1, message.Header.AnswerCount, "Header.AnswerCount");
            Assert.AreEqual(1, message.Header.AuthorityCount, "Header.AuthorityCount");
            Assert.AreEqual(1, message.Header.ResourceCount, "Header.ResourceCount");

            Assert.AreEqual(1, message.Questions.Count, "Questions.Count");
            Assert.AreEqual(1, message.Answers.Count, "Answers.Count");
            Assert.AreEqual(1, message.Authorities.Count, "Authorities.Count");
            Assert.AreEqual(1, message.Additionals.Count, "Additionals.Count");
        }

        [Test]
        public void TestGetBytes() {


            var generator = new SelfAnsweringQuestion();
            byte[] bs = generator.GetBytes();
            IMessage source = generator.GetMessage();

            var mem = new MemoryStream(bs);
            IMessage recomputed = DnsReader.Read(mem);

            MessageHelper.DeepCompare(source, recomputed);

        }

    }
}
